package com.tjsinfo.tjsoa.system.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.system.bo.ISystemUserDepartmentBo;
import com.tjsinfo.tjsoa.system.vo.TSystemUserDepartment;

/**、
 * 用户部门查询
 * @author Administrator
 *
 */
public class SelectUserDepartmentAction extends Action{
	private ISystemUserDepartmentBo systemUserDepartmentBo;
	
	public ISystemUserDepartmentBo getSystemUserDepartmentBo() {
		return systemUserDepartmentBo;
	}

	public void setSystemUserDepartmentBo(
			ISystemUserDepartmentBo systemUserDepartmentBo) {
		this.systemUserDepartmentBo = systemUserDepartmentBo;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		Integer userid = Integer.parseInt(request.getParameter("userid")); 
		List<TSystemUserDepartment> systemUserDepartmentList =  systemUserDepartmentBo.selectByUserId(userid);
		JSONArray array = new JSONArray();
		Integer orderid = 1;
		for (TSystemUserDepartment systemUserDepartment : systemUserDepartmentList) {
			JSONObject object = new JSONObject();
			object.put("orderNo", orderid);
			object.put("deptName", systemUserDepartment.getDepartmentName());
			object.put("id", systemUserDepartment.getId());
			object.put("deptId", systemUserDepartment.getDepartmentId());
			object.put("operate", "<a href='javascript:remove("+systemUserDepartment.getDepartmentId()+")'>移除</a>");
			orderid++;
			array.put(object);
		}
		response.getWriter().print(array);
		return null;
	}
	
}
